<template>
  <RouterView v-if="isRouterAlive"></RouterView>
  <div v-show="!$route.meta.flag">
    <van-tabbar v-model="active" route>
      <van-tabbar-item icon="home-o" to="/home">首页</van-tabbar-item>
      <van-tabbar-item icon="cart-o" to="/cart">购物车</van-tabbar-item>
      <van-tabbar-item icon="manager-o" v-if="goPage" to="/mine">我的</van-tabbar-item>
      <van-tabbar-item icon="manager-o" v-else to="/login">登录</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 0,
      isRouterAlive: true   //这个属性可以自己取名字
    }
  },

  // 通过provide吧reload返回出去
  provide() {
    return {
      reload: this.reload
    }
  },

  methods: {
    // 刷新页面
    reload() {
      this.isRouterAlive = false
      this.$nextTick(function () {
        this.isRouterAlive = true
      })
    },
  },

  // 通过token判断有没有登录
  computed: {
    goPage() {
      return localStorage.getItem('token')
    }
  }
}

</script>
<style>
body,
html,
.app {
  background-color: #F6F6F6;
  overflow-y: auto;
}
</style>